package aptech.eproject.logictics.db;

import java.io.Serializable;
import javax.persistence.*;
import java.util.Set;


/**
 * The persistent class for the ROUTE database table.
 * 
 */
@Entity
@Table(name="ROUTE")
public class Route implements Serializable {
	private static final long serialVersionUID = 1L;
	private int routeId;
	private double distance;
	private boolean isDeleted;
	private Branch toBranch;
	private Branch fromBranch;
	private Set<TripRoute> tripRoutes;

    public Route() {
    }

    public Route(Branch fromBranch,Branch toBranch,double  distance)
     {
        this.fromBranch=fromBranch;
        this.toBranch=toBranch;
        this.distance=distance;
     }


	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="ROUTE_ID")
	public int getRouteId() {
		return this.routeId;
	}

	public void setRouteId(int routeId) {
		this.routeId = routeId;
	}


	@Column(name="DISTANCE",nullable=false)
	public double getDistance() {
		return this.distance;
	}

	public void setDistance(double distance) {
		this.distance = distance;
	}


	@Column(name="IS_DELETED",nullable=true)
	public boolean getIsDeleted() {
		return this.isDeleted;
	}

	public void setIsDeleted(boolean isDeleted) {
		this.isDeleted = isDeleted;
	}


	//bi-directional many-to-one association to Branch
    @ManyToOne
	@JoinColumn(name="TO_BRANCH_ID",nullable=false)
	public Branch getToBranch() {
		return toBranch;
	}	

    public void setToBranch(Branch toBranch) {
		this.toBranch = toBranch;
	}
    
	//bi-directional many-to-one association to Branch
    @ManyToOne
	@JoinColumn(name="FROM_BRANCH_ID",nullable=false)
	public Branch getFromBranch() {
		return fromBranch;
	}
    public void setFromBranch(Branch fromBranch) {
		this.fromBranch = fromBranch;
	}
	

	//bi-directional many-to-one association to TripRoute
	@OneToMany(mappedBy="route", fetch=FetchType.EAGER)
	public Set<TripRoute> getTripRoutes() {
		return this.tripRoutes;
	}

	public void setTripRoutes(Set<TripRoute> tripRoutes) {
		this.tripRoutes = tripRoutes;
	}
	
	public TripRoute addTripRoute(TripRoute tripRoute)
	{
		getTripRoutes().add(tripRoute);
		return tripRoute;
	}
	
	public TripRoute removeTripRoute(TripRoute tripRoute)
	{
		getTripRoutes().remove(tripRoute);
		tripRoute.setRoute(null);
		return tripRoute;	
	}
}